﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.IO;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Library.Utilities;
using NCS.Module.CMS.Library.Contents;
using NCS.Module.Multimedia.Library.Gallery;
using NCS.Module.CMS.Library;
using NCS.Library;
using NCS.Module.Multimedia.Library;

namespace NCS.Module.Multimedia.Web.Gallery
{
    public partial class ListGalery : GalleryWebControl
    {
        private string userUploadPath = Library.Definies.UploadPath;
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (!IsPostBack)
            {
                int contentid = 0;
                // check album theo bai viet, neu chua co album thi tao moi
                if (Request.QueryString["contentid"] != null && Request.QueryString["contentid"] != "")
                {
                    contentid = ConvertUtility.ToInt32(Request.QueryString["contentid"]);
                }


                if (contentid > 0)
                {
                    ContentInfo cinfo = ContentController.GetContent(contentid);
                    Gallery_AlbumInfo chkinfo = Gallery_AlbumController.GetAlbumByOtherID(contentid);

                    if (chkinfo == null)
                    {
                        Gallery_AlbumInfo ainfo = new Gallery_AlbumInfo();
                        ainfo.AlbumAvatar = "";
                        ainfo.AlbumDetail = "";
                        ainfo.AlbumName = cinfo.Content_Headline;
                        ainfo.CreateUserID = CurrentUser.UserID;
                        ainfo.ModifyUserID = CurrentUser.UserID;
                        ainfo.PortalID = ConvertUtility.ToInt32(AppEnv.PortalId());
                        ainfo.IsComment = false;
                        ainfo.Lang = AppEnv.GetLanguage();
                        ainfo.Visible = true;
                        ainfo.Other_ID = contentid;
                        albumid = Gallery_AlbumController.InsertAlbum(ainfo);
                    }
                }

                this.link_zone.Text = Gallery_AlbumController.GetAlbumName(this.albumid);
            }

            dtgPicList.DataSource = PictureController.Picture_GetAllByAlbumID(ConvertUtility.ToInt32(albumid));

            dtgPicList.DataBind();
        }
    }
}